package com.woniuxy.mesboot.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.woniuxy.mesboot.dto.OrdersDTO;
import com.woniuxy.mesboot.dto.OrdersDetailsDTO;
import com.woniuxy.mesboot.entity.MesOrders;
import com.woniuxy.mesboot.mapper.MesOrdersMapper;
import com.woniuxy.mesboot.mapper.MesOrdersdetailMapper;
import com.woniuxy.mesboot.service.OrderService;
import com.woniuxy.mesboot.vo.OrdersDetailsVO;
import com.woniuxy.mesboot.vo.OrdersTicketVO;
import com.woniuxy.mesboot.vo.OrdersVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 黑川
 * @version : 1.0
 * @Project : mes-boot
 * @Package : com.woniuxy.mesboot.service.impl
 * @ClassName : .java
 * @createTime : 2023/5/23 17:40
 * @Description :
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private MesOrdersMapper ordersMapper;
    @Resource
    private MesOrdersdetailMapper ordersdetailMapper;


    @Override
    public OrdersTicketVO selectOrderTickets(String ordersNo) {
        return ordersMapper.selectOrderTickets(ordersNo);
    }

    @Override
    public List<OrdersDetailsVO> selectAllByDetails(String ordersNo) {
        return ordersMapper.selectAllByDetails(ordersNo);
    }

    public List<OrdersVO> selectAll(OrdersDTO orders) {
        return ordersMapper.selectAll(orders);
    }

    public int deleteByPrimaryKey(String ordersNo) {
        int i = ordersMapper.deleteByPrimary(ordersNo);
        if (i>0){
            ordersdetailMapper.deleteByOrdersNo(ordersNo);
        }
        return i;
    }

    public int insert(MesOrders record) {
        return ordersMapper.insert(record);
    }

    public int insertSelective(OrdersDetailsDTO detailsDTO) {
        String ordersNo = DateUtil.format(new Date(), "yyyyMMddHHmmss")+ RandomUtil.randomNumbers(4);
        detailsDTO.setOrdersNo(ordersNo);
        return ordersMapper.insertSelective(detailsDTO);
    }

    public MesOrders selectByPrimaryKey(String ordersNo) {
        return ordersMapper.selectByPrimaryKey(ordersNo);
    }

    public int updateByPrimaryKeySelective(MesOrders record) {
        return ordersMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(MesOrders record) {
        return ordersMapper.updateByPrimaryKey(record);
    }
}
